import React, { Component } from 'react'

export default class Comment extends Component {
	state = {
		second: this.JobTime(this.props.comment.stamp),
	}
	componentDidMount() {
		this.Timer = setInterval(() => {
			this.setState({
				second: this.JobTime(this.props.comment.stamp),
			})
		}, 5000)
	}
	componentWillUnmount() {
		if (this.Timer) {
			clearInterval(this.Timer)
		}
	}
	// 时间显示函数
	JobTime(stamp) {
		return Math.ceil((Date.now() - stamp) / 1000 / 60)
	}
	render() {
		return (
			<div className="comment">
				<div className="comment-user">
					<span>{this.props.comment.username} </span>：
				</div>
				<p>{this.props.comment.content}</p>
				<p>------{this.state.second}分钟之前</p>
				<span
					className="comment-delete"
					onClick={() => this.props.handelDel(this.props.comment)}
				>
					删除
				</span>
			</div>
		)
	}
}
